package Leetcode;

public class problem12 {
    public static String intToRoman(int num) {
        StringBuilder sb = new StringBuilder();
        int[] nums = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
        String[] roman = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
        for(int i = 0 ; i < nums.length ; i ++) {
            int currentNum = nums[i];
            if(num >= currentNum) {
                int temp = num / nums[i];
                for(int j = 0 ; j < temp ; j ++) {
                    sb.append(roman[i]);
                }
                num = num - temp * currentNum;
            }
        }

        return sb.toString();
    }

    public static void main(String[] args) {
        intToRoman(5);
    }
}
